<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:th="http://www.thymeleaf.org"
	xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
	layout:decorator="layouts/layout"
	th:with="header=盘点导入, subtext='从上传文件中导入物料数据'">

<head>
<title>盘点数据导入</title>
<link th:href="@{|${theme}/css/plugins/jasny/jasny-bootstrap.min.css|}"
	href="/themes/inspinia/css/plugins/jasny/jasny-bootstrap.min.css"
	rel="stylesheet">
</head>

<body>
	<th:block layout:fragment="content">
		<div class="row">
			<div class="col-lg-12">
				<div class="box">
					<div class="box-body">
						<div th:if="${list==null}">
							<form id="uploadForm" th:action="@{|${baseUrl}/ca/upload|}" method="post"
								enctype="multipart/form-data">
								<h2>1. 请选择需要导入文件并上传!
								<div class="pull-right p-xs"><a th:href="@{|${baseUrl}|}" class="btn btn-primary" ><i class="fa fa-fw fa-reply"></i>返回</a></div>
								</h2>
								<hr />
								<div class="row">
									<div class="col-md-6">
										<div class="fileinput fileinput-new input-group"
											data-provides="fileinput">
											<div class="form-control" data-trigger="fileinput">
												<i class="glyphicon glyphicon-file fileinput-exists"></i> <span
													class="fileinput-filename"></span>
											</div>
											<span class="input-group-addon btn btn-default btn-file">
												<span class="fileinput-new">选择文件</span> <span
												class="fileinput-exists">重新选择</span> <input id="file"
												type="file" name="file">
											</span> <a href="#"
												class="input-group-addon btn btn-default fileinput-exists"
												data-dismiss="fileinput">清除</a>
										</div>
									</div>
									<div class="col-md-6">
										<button id="submit" type="submit" class="btn btn-info" th:title="导入数据"
											data-toggle="modal" data-target="#importModal">
											<i class="fa fa-fw fa-cloud-upload"></i> 上传文件
										</button>
										<a id="downloadTemplate" class="btn btn-primary btn-sm"
											th:href="@{|/static/inventory/count.xls|}" th:title="下载模板"> <i
											class="fa fa-fw fa-cloud-download"></i>下载模板
										</a>
										&nbsp;&nbsp;&nbsp;
										<input type="checkbox" id="chkUpdate" name="chkUpdate" value="1" />&nbsp;<span>重复时更新旧数据</span>
									</div>
								</div>
							</form>
						</div>
						<div id="tableWrapper" th:if="${dataList!=null}">
							<div class="pull-right p-xs">
								<a th:href="@{|${baseUrl}/import|}" class="btn btn-primary"><i
									class="fa fa-fw fa-reply"></i>返回</a>
							</div>
							<h2 th:if="${hasError}"
								th:class="${hasError?'p-xs b-r-sm bg-danger':'p-xs b-r-sm'}">2.
								已读入数据文件内容，请检查错误！</h2>
							<h2 th:if="${not hasError}" class="p-xs b-r-sm">2.
								已导入的数据文件内容</h2>
							<hr />
							<table id="table" class="table table-striped table-hover">
								<thead>
									<tr>
										<th>物料编码</th>
										<th>容器编码</th>
									</tr>
								</thead>
								<tbody>
									<tr th:each="o : ${dataList}">
										<td th:text="${o.materialCode}"></td>
										<td th:text="${o.containerNumber}"></td>
										<td th:text="${o.status}"></td>
										<td style="color: red">
											<div th:each="e : ${o.errs}">
												<span th:text="${e.message}" />;
											</div> <span th:text="${o.errorMessage}" style="color: red" />
										</td>
									</tr>
								</tbody>
							</table>
						</div>
					</div>
				</div>
			</div>
		</div>
	</th:block>
	<th:block layout:fragment="scripts">
		<!-- Jasny -->
		<script th:src="@{|${theme}/plugins/jasny/jasny-bootstrap.min.js|}"></script>
		<script th:inline="javascript">
			$(document).ready(function() {
				var table = $('table#table').DataTable({
					dom : defaultDom,
					autoWidth : false,
					processing : false,
					pageLength : 100,
					lengthChange : true,
					searching : true,
					serverSide : false
				});
				var form=$("#uploadForm")
				//提示上传文件为空
				// 提交当前活动的form，多个tab时候需要知道当前的tab
				$("#submit").on("click", function(e) {
					var file = $("#file").val();
					if (file == "" || file == null) {
						bootbox.alert("上传文件为空");
						return false;
					}
					form.submit();
				});
			});
		</script>
	</th:block>
</body>

</html>
